home *** CD-ROM | disk | FTP | other *** search
/ Varios Español / Varios Español.iso / DBASE5 / CUA_SAMP.ZIP / FILETYPE.PRG < prev    next >
Text File  |  1994-10-12  |  2KB  |  56 lines

  1. FUNCTION FileType
  2. PARAMETER pc_fname
  3. *--------------------------------------------------------------------
  4. * NAME
  5. *   FileType - Returns extension of a file name or spec.
  6. *
  7. * SYNOPSIS
  8. *   FileType( pc_fname )
  9. *
  10. * DESCRIPTION
  11. *   FileType() returns the extension of the file name
  12. *   specified by pc_fname.  It may be up to three
  13. *   characters long.
  14. *
  15. *   The file name may be preceded by a DOS file path.
  16. *
  17. *   The current implementation will return all upper-
  18. *   case letters.
  19. *
  20. * PARAMETER
  21. *   pc_fname - A character file name or DOS file spec.
  22. *
  23. * EXAMPLE
  24. *   lc_ext = FileType( "C:\TEST\FOO.PRG" )
  25. *     ( lc_ext will equal "PRG" )
  26. *
  27. *   lc_ext = FileType( "MYFILE.XX" )
  28. *     ( lc_ext will equal "XX" )
  29. *
  30. * SEE ALSO
  31. *   _FILEDRV(), _FILEPATH(), _FILEROOT()
  32. *
  33. *--------------------------------------------------------------------
  34.     PRIVATE ln_dotpos, ln_lensrc, cResult
  35.  
  36.     ln_lensrc = LEN( m->pc_fname )
  37.     ln_dotpos = RAT( ".", m->pc_fname )
  38.     lc_slash = "\"
  39.     nLastSlash = RAT( "\", m->pc_fName )
  40.  
  41.     DO CASE
  42.         CASE m->ln_dotpos = 0              && No extension
  43.             cResult = ""
  44.         CASE m->nLastSlash > m->ln_dotpos     && The dot is part of the path
  45.             cResult = ""
  46.         OTHERWISE
  47.             cResult = UPPER( SUBSTR(  m->pc_fname, m->ln_dotpos + 1 ) )
  48.             IF LEN( m->cResult ) > 3 .AND. m->lc_slash = "\"
  49.                 cResult = LEFT( m->cResult, 3 )
  50.             ENDIF
  51.     ENDCASE
  52.  
  53. RETURN m->cResult
  54. *-- EOF: FileType( pc_fname )
  55.  
  56.